package com.avcdata.aoscustommade.utils;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;

/**
 * 动画工具类
 */
public class AnimationUtil {

	/**
	 * 弹出动画效果
	 */
	public static void showAnimation(View view) {
		AnimationSet animationSet = new AnimationSet(true);
		TranslateAnimation translateAnimation = new TranslateAnimation(
				Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,
				Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f);
		translateAnimation.setDuration(400);
		animationSet.addAnimation(translateAnimation);
		view.startAnimation(animationSet);
	}
	
	/**
	 * 退出动画效果
	 */
	public static void backAnimation(View view) {
		AnimationSet animationSet = new AnimationSet(true);
		TranslateAnimation translateAnimation = new TranslateAnimation(
				Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,
				Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1f);
		translateAnimation.setDuration(400);
		animationSet.addAnimation(translateAnimation);
		view.startAnimation(animationSet);
	}


	/**
	 * 开始播放模式选择动画
	 *
	 * @param view       目标View
	 * @param isSelected 是否选择
	 */
	public static void startModeSelectAnimation(View view, boolean isSelected) {
		RotateAnimation rotate;
		if (isSelected) {
			rotate = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f,
					Animation.RELATIVE_TO_SELF, 0.5f);
		} else {
			rotate = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF,
					0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		}
		rotate.setFillAfter(true);
		rotate.setDuration(200);
		view.startAnimation(rotate);
	}



	/**====Tab页动画==== */
	public static int in = 0;
	public static int out = 0;

	public static void set(int a, int b) {
		in = a;
		out = b;
	}

	public static void clear() {
		in = 0;
		out = 0;
	}

//	public static void JudgeTypeView(Activity context,View view) {
//		if (view.getVisibility() == View.VISIBLE) {
//			SetTypeViewGone(context,view);
//		} else {
//			Animation top_inan_imation = AnimationUtils.loadAnimation(context, R.anim.enter_dropdown);
//			view.startAnimation(top_inan_imation);
//			view.setVisibility(View.VISIBLE);
//		}
//	}
//
//
//	public static void SetTypeViewGone(Activity context,View view) {
//		if (view.getVisibility() == View.VISIBLE) {
//			Animation top_out_animation = AnimationUtils.loadAnimation(context, R.anim.exit_dropup);
//			view.startAnimation(top_out_animation);
//			view.setVisibility(View.GONE);
//		}
//	}



//	public void showIndicator() {
//		//属性动画translationY
//		ObjectAnimator animator = ObjectAnimator.ofFloat(indicator, "translationY",
//				0f);
//		//持续时间
//		animator.setDuration(500);
//		//插值器，减速
//		animator.setInterpolator(new DecelerateInterpolator(2));
//		//监听器
//		animator.addUpdateListener(new AnimatorUpdateListener() {
//			@Override
//			public void onAnimationUpdate(ValueAnimator animation) {
//				//不断增加indicator所在viewgroup的高度
//				LayoutParams layoutParams = indicator.getLayoutParams();
//				float v=(Float) animation.getAnimatedValue();
//				Log.d("TAG","show:"+v);
//				layoutParams.height=height+(int)v;
//				//重新布局
//				indicator.requestLayout();
//			}
//		});
//		animator.addListener(new AnimatorListenerAdapter() {
//			@Override
//			public void onAnimationStart(Animator animation) {
//				//动画开始后设置为true
//				isShowing=true;
//				super.onAnimationStart(animation);
//			}
//			@Override
//			public void onAnimationEnd(Animator animation) {
//				//动画结束后设置为false
//				isShowing=false;
//				//显示后设置为已显示
//				isIndicatorShow = true;
//				super.onAnimationEnd(animation);
//			}
//
//		});
//		//开始动画
//		animator.start();
//
//	}

//	public void hideIndicator() {
//
//		ObjectAnimator animator = ObjectAnimator.ofFloat(indicator, "translationY",-height);
//		animator.setDuration(500);
//		//加速插值器
//		animator.setInterpolator(new AccelerateInterpolator(2));
//		animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
//
//			@Override
//			public void onAnimationUpdate(ValueAnimator animation) {
//				//不断减小indicator所在viewgroup的高度
//				LayoutParams layoutParams = indicator.getLayoutParams();
//				float v=(Float) animation.getAnimatedValue();
//				Log.d("TAG","hide:"+v);
//				layoutParams.height=height+(int)v;
//				indicator.requestLayout();
//			}
//		});
//		//同显示
//		animator.addListener(new AnimatorListenerAdapter() {
//			@Override
//			public void onAnimationStart(Animator animation) {
//				isShowing=true;
//				super.onAnimationStart(animation);
//			}
//
//			@Override
//			public void onAnimationEnd(Animator animation) {
//				isShowing=false;
//				isIndicatorShow = false;
//				super.onAnimationEnd(animation);
//			}
//
//
//		});
//		animator.start();
//
//	}




}
